import enumJson from '../../devOpsResource/data/enum';


export default [
    {id:'unitName',label:'单位名称',width:180,value:'',required:true,sortable:true,editorType:'input',show:true},
    {id:'unitId',label:'单位ID',width:160,value:'',required:true,sortable:true,editorType:'input',show:true},
    {id:'unitProductCode',label:'单位产品编号',width:160,value:'',required:true,sortable:true,editorType:'input',show:true},
    {id:'unitOrgCode',label:'单位产品码',width:160,value:'',required:true,sortable:true,editorType:'input',show:true},
    {id:'productCode',label:'产品编号',width:160,value:'1',required:true,sortable:true,editorType:'input',show:true},
    {id:'productName',label:'产品名称',width:160,value:'',required:true,sortable:true,editorType:'input',show:true},
    {id:'productStatus',label:'状态',width:100,value:'1',required:true,sortable:true,editorType:'stateSelect',show:true,getState:(value)=>{
            if((value+"")==="0"){
                return 'error'
            }else if((value+"")==="1"){
                return 'normal'
            }else if((value+"")==="2"){
                return 'warning'
            }else if((value+"")==="3"){
                return 'warning'
            }
        },getLabel:(value)=>{
            if((value+"")==="0"){
                return '未启用'
            }else if((value+"")==="1"){
                return '在用'
            }else if((value+"")==="2"){
                return '自动停用'
            }else if((value+"")==="3"){
                return '手动停用'
            }
        },cellFun:(rowRecord,itemd)=>{
            if((rowRecord[itemd]+"")==="0"){
                return '未启用'
            }else if((rowRecord[itemd]+"")==="1"){
                return '在用'
            }else if((rowRecord[itemd]+"")==="2"){
                return '自动停用'
            }else if((rowRecord[itemd]+"")==="3"){
                return '手动停用'
            }
        }},
    {id:'orderCode',label:'订单编号',width:140,value:'1',required:true,sortable:true,editorType:'input',show:true},
]
//分配资源 的form列表
let formCols=[
    {id:'workLoad',queryType:enumJson["workLoad"],tenantProductCode:'',tenantId:'',label:'工作负载',width:100,value:'',remark:'请确保同一工作负载下的所有租户产品使用同一个redis实例',required:false,disabled:false,sortable:true,editorType:'filterSelect',show:true},
    {id:'schema',queryType:'8',tenantProductCode:'',tenantId:'',label:'数据库Schema',width:100,value:'',required:false,disabled:false,sortable:true,editorType:'filterSelect',show:true},
    {id:'cacheCluster',queryType:enumJson["cacheCluster"],tenantProductCode:'',tenantId:'',label:'缓存集群',width:100,value:'',required:false,disabled:false,sortable:true,editorType:'filterSelect',show:true},
    {id:'domain',queryType:enumJson["domain"],tenantProductCode:'',tenantId:'',label:'域名',width:100,value:'',required:false,disabled:false,sortable:true,editorType:'filterSelect',show:true},
    {id:'appDir',queryType:enumJson["appDir"],tenantProductCode:'',tenantId:'',label:'应用目录',width:100,value:'',required:false,disabled:false,sortable:true,editorType:'filterSelect',show:true},
    {id:'dataDir',queryType:enumJson["dataDir"],tenantProductCode:'',tenantId:'',label:'数据目录',width:100,value:'',required:false,disabled:false,sortable:true,editorType:'filterSelect',show:true},
    {id:'contextPath',queryType:enumJson["contextPath"],tenantProductCode:'',tenantId:'',label:'contextpath',width:100,value:'',disabled:false,required:false,sortable:true,editorType:'filterSelect',show:true},

];
export {formCols};

/**
 * 生成uuid
 * @returns {string}
 */
function uuid() {
    var s = [];
    var hexDigits = "0123456789abcdef";
    for (var i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23] = "-";

    var uuid = s.join("");
    return uuid;
}
export {uuid};

let _initColWidth=function (cols,rightWid=0) {
    let totalWidth=document.body.clientWidth-240-180-rightWid;
    let colTotalWid=0;
    cols.forEach((item)=>{
        colTotalWid=parseFloat(colTotalWid)+parseFloat(item.width)
    });
    //如果存在多余的宽度，则将多余的宽度平均分配到其他列去
    if(colTotalWid<totalWidth){
        let oWid=totalWidth-colTotalWid;
        let oWidNum=oWid/cols.length;
        cols.forEach((itemObj)=>{
            itemObj["width"]=itemObj["width"]+oWidNum;
        })
    }
}
export {_initColWidth};

/**
 * 获取分配资源的id集合
 * @param cols
 * @returns {Array}
 * @private
 */
let _changToAddDomain=function (cols) {
    let arryStrs=[];
    cols.forEach((itemObj,index)=>{
        if(itemObj["value"]!=null&&itemObj["value"]!==""){
            if(itemObj["value"].indexOf("已分配")>=0){
            }else{
                arryStrs.push(itemObj["value"]);
            }
        }
    });
   return arryStrs;
}

export {_changToAddDomain};

let _getCloneCols=function (cols) {
    let newCols=[];
    cols.forEach((itemObj)=>{
        newCols.push({...itemObj});
    })
    return newCols;
}

export {_getCloneCols};